package com.ma.sharenote.usercenter.controller.content;

import com.ma.sharenote.usercenter.domain.dto.content.ShareDTO;
import com.ma.sharenote.usercenter.service.content.ShareService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/shares")
@RequiredArgsConstructor(onConstructor = @_(@Autowired))
public class ContentController {

    private final ShareService shareService;

    private final DiscoveryClient discoveryClient;

    @RequestMapping("/{id}")
    public ShareDTO findById(@PathVariable Integer id){
        return shareService.findById(id);
    }

    @RequestMapping("/test")
    public List<ServiceInstance> getInstande(){
        return discoveryClient.getInstances("user-center");
    }

}
